<template>
  <div>
    <h1>当前求和为：{{sum}}</h1>
    <select v-model="n">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="increament">+</button>
    <button @click="decreament">-</button>
    <button @click="increamentOdd">当前求和为奇数再加</button>
    <button @click="increamentWait">等一等再加</button>
  </div>
</template>

<script>
  export default {
    name: "Count",
    data() {
      return {
        n: 1,   // 用户选择的数字
        sum: 0  // 当前的和
      }
    },
    methods: {
      increament() {
        // this.sum = this.sum + this.n
        this.sum += this.n
      },
      decreament() {
        // this.sum = this.sum - this.n
        this.sum -= this.n
      },
      increamentOdd() {
        if(this.sum % 2 == 0) {
          this.sum += this.n
        }
      },
      increamentWait() {
        setTimeout(()=> {
          this.increament()
        }, 1000)
      },
    }
  }
</script>

<style lang="css">
  button {
    margin: 5px;
  }

</style>